package com.lineage.server.model.skill.skillmode;

import com.lineage.config.ConfigKnightSkill;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Magic;
import com.lineage.server.serverpackets.S_Paralysis;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.utils.L1SpawnUtil;
import java.util.Random;

public class SHOCK_STUN extends SkillMode {
  private int[] sec = ConfigKnightSkill.SHOCK_STUN_TIMER;
  
  public int start(L1PcInstance srcpc, L1Character cha, L1Magic magic, int integer) throws Exception {
    int dmg = 0;
    L1ItemInstance weapon = srcpc.getWeapon();
    if (weapon != null && weapon.getItem().getType() == 3) {
      if (cha.hasSkillEffect(8002))
        return 0; 
      Random random = new Random();
      int shock = random.nextInt(this.sec[1]) + this.sec[0];
      if (shock > this.sec[1])
        shock = this.sec[1]; 
      if (srcpc.isGm())
        srcpc.sendPackets((ServerBasePacket)new S_ServerMessage("此次冲晕秒数为" + shock + "秒..只有GM看的到")); 
      cha.setSkillEffect(87, shock * 1000);
      L1SpawnUtil.spawnEffect(81162, shock, cha.getX(), cha.getY(), cha.getMapId(), cha, 0);
      if (cha instanceof L1PcInstance) {
        L1PcInstance pc = (L1PcInstance)cha;
        pc.sendPackets((ServerBasePacket)new S_Paralysis(5, true));
      } else if (cha instanceof com.lineage.server.model.Instance.L1MonsterInstance || cha instanceof com.lineage.server.model.Instance.L1SummonInstance || 
        cha instanceof com.lineage.server.model.Instance.L1PetInstance) {
        L1NpcInstance tgnpc = (L1NpcInstance)cha;
        tgnpc.setParalyzed(true);
      } 
    } 
    return 0;
  }
  
  public int start(L1NpcInstance npc, L1Character cha, L1Magic magic, int integer) throws Exception {
    int dmg = magic.calcMagicDamage(87);
    if (cha.hasSkillEffect(8002))
      return dmg; 
    Random random = new Random();
    int shock = random.nextInt(4) + 1;
    if (cha instanceof L1PcInstance && cha.hasSkillEffect(87))
      shock += cha.getSkillEffectTimeSec(87); 
    if (shock > 6) {
      shock = 6;
      cha.setSkillEffect(8002, shock * 1000);
    } 
    cha.setSkillEffect(87, shock * 1000);
    L1SpawnUtil.spawnEffect(81162, shock, cha.getX(), cha.getY(), cha.getMapId(), cha, 0);
    if (cha instanceof L1PcInstance) {
      L1PcInstance pc = (L1PcInstance)cha;
      pc.sendPackets((ServerBasePacket)new S_Paralysis(5, true));
    } else if (cha instanceof com.lineage.server.model.Instance.L1MonsterInstance || cha instanceof com.lineage.server.model.Instance.L1SummonInstance || 
      cha instanceof com.lineage.server.model.Instance.L1GuardianInstance || cha instanceof com.lineage.server.model.Instance.L1GuardInstance || 
      cha instanceof com.lineage.server.model.Instance.L1PetInstance) {
      L1NpcInstance tgnpc = (L1NpcInstance)cha;
      tgnpc.setParalyzed(true);
    } 
    return 0;
  }
  
  public void start(L1PcInstance srcpc, Object obj) throws Exception {}
  
  public void stop(L1Character cha) throws Exception {
    if (cha instanceof L1PcInstance) {
      L1PcInstance pc = (L1PcInstance)cha;
      pc.sendPackets((ServerBasePacket)new S_Paralysis(5, false));
    } else if (cha instanceof com.lineage.server.model.Instance.L1MonsterInstance || cha instanceof com.lineage.server.model.Instance.L1SummonInstance || 
      cha instanceof com.lineage.server.model.Instance.L1GuardianInstance || cha instanceof com.lineage.server.model.Instance.L1GuardInstance || 
      cha instanceof com.lineage.server.model.Instance.L1PetInstance) {
      L1NpcInstance npc = (L1NpcInstance)cha;
      npc.setParalyzed(false);
    } 
  }
}
